package com.briup.product_my.service.impl;

import com.briup.product_my.domain.ManagerBatch;
import com.briup.product_my.domain.ManagerFenceHouse;
import com.briup.product_my.domain.QuarantineRegistration;
import com.briup.product_my.mapper.ManagerBatchMapper;
import com.briup.product_my.mapper.QuarantineRegistrationMapper;
import com.briup.product_my.service.QuarantineRegistrationService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Auther: xiongwenbin
 * @Date: 2024/8/22-08-22-下午2:38
 * @Description: com.briup.product_my.service.impl
 */
@Service
public class QuarantineRegistrationServiceImpl implements QuarantineRegistrationService {
    @Autowired
    private QuarantineRegistrationMapper quarantineRegistrationMapper;
    @Autowired
    private ManagerBatchMapper managerBatchMapper;
    @Override
    public void saveOrUpdate(QuarantineRegistration quarantineRegistration) {
        if(quarantineRegistration.getGrId() == null){
            quarantineRegistration.setGrId(quarantineRegistrationMapper.getMaxGrId()+1);
            quarantineRegistrationMapper.insert(quarantineRegistration);
            ManagerBatch managerBatch = managerBatchMapper.selectBy(quarantineRegistration.getGrBatchId());
            managerBatch.setBQuarantine("已检疫");
            managerBatchMapper.updateByPrimaryKeySelective(managerBatch);
        }else {
            quarantineRegistrationMapper.updateByPrimaryKeySelective(quarantineRegistration);
        }
    }

    @Override
    public PageInfo<QuarantineRegistration> findAll(Integer pageNum, Integer pageSize,String bQualified,String grMechanism) {
        // PageHelper开启分页
        PageHelper.startPage(pageNum, pageSize);
        // 核心查询语句
        List<QuarantineRegistration> quarantineRegistrations = quarantineRegistrationMapper.findAll(bQualified,grMechanism);
        // 将查询的信息封装在PageInfo对象中，返回
        PageInfo<QuarantineRegistration> pageInfo = new PageInfo<>(quarantineRegistrations);
        return pageInfo;
    }

    @Override
    public void delete(Integer id) {
        quarantineRegistrationMapper.deleteById(id);
    }

    @Override
    public void deleteByIdAll(Integer[] ids) {
        quarantineRegistrationMapper.deleteByIdAll(ids);
    }
}
